
import 'package:Smart/res/colors_res.dart';
import 'package:Smart/utils/routers/page_jump_service.dart';
import 'package:flutter/material.dart';
import 'package:Smart/utils/screen_unit/gs_screen_util.dart';

import 'bluetooth/gs_bluetooth_page.dart';

class MyDiyPage extends StatefulWidget {
  @override
  _MyDiyPageState createState() => _MyDiyPageState();
}

class _MyDiyPageState extends State<MyDiyPage> {

  List listData = [
    {"title": "蓝牙","num":1},
    {"title": "功能二","num":2},
    {"title": "功能三","num":3},
    {"title": "功能4","num":4},
  ];

  @override
  Widget build(BuildContext context) {
    return GridView.count(
      //水平子Widget之间间距
        crossAxisSpacing: 10.w,
        //垂直子Widget之间间距
        mainAxisSpacing: 30.w,
        //GridView内边距
        padding: EdgeInsets.all(10.w),
        //一行的Widget数量
        crossAxisCount: 3,
        //子Widget宽高比例
        childAspectRatio: 1.0,
        children: listData.map((element) {
          return listItem(
              element["title"],
              onTap: (){
                itemAction(context, element["num"]);
              }
          );
        }).toList()
    );
  }

  // ListItem
  Widget listItem(String title, {Function onTap}) {
    return ListTile(
      contentPadding: EdgeInsets.all(0),
      title: Container(
        // margin: EdgeInsets.all(0),
        // padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
        child: Center(child: Text(title,style: TextStyle(fontSize: 24.w),)),
        color: Colors.purple,
      ),
       onTap: onTap,
    );
  }

  // Item事件相应
  void itemAction(BuildContext context, int index) {
    if (index == 1) {
      PageJumpService.instance().goTo(GsMyBluttoothPage());
    }
  }

}
